-
Notifications
You must be signed in to change notification settings - Fork 46.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Cannot read property 'useState' of null #24928
Comments
I have a bug with same error message, but all the libraries use react18. I'll describe an architecture and here is a link to an example. Can you take a look, does it relative to the issue? ArchSo, I have react18, webpack5, umd. There are several projects that linked together as local delendencies. I link projects using I'm not really sure how webpack-es6 tree-shaking works, but I decided to create a bundle per source file instead of creating bundle per project. Just, well, it seems that webpack will understand it, probably. So, there is no Projects
If you make a change in a project, be sure to build the project using Run./bootstrap.sh # it will initialize and build all the projects
cd application
yarn start ErrorThere's a react hook. When the hook imports from
So...here we are. If you need any further details - just ask) |
This problem also occurred to me, stops package development completely. Need help! |
The problem is that when using local packages, |
hi! @rollsover Thank you for your method!But if delete a node_modules it will not be possible to continue development, can you tell me how you do it? |
To get rid of |
Thanks for this @Kiran554 was driving me mad. |
The workaround for me is to remove dependencies in the the package.json using prepack script and pack the library with |
I could finally solve this issue with @rollsover 's workaround. Thank you!
|
I am facing the same issue with my package. Please help. |
I think this should be fixed if the corresponding dependencies set react as peer dependeny
|
The reason for this problem is that the react version in the project is inconsistent with the react version used in your package If you use your package in a project and a certain version of react has been installed in the project. Then you install your package in this project, and a certain version of react is also installed in your package. Then you may get this error report how to fix it?You just need to put the react dependencies from your package into the peerDependencies bad caseproject {
"dependencies": {
"react": "x.x.x",
"react-dom": "x.x.x",
"your package": "x.x.x"
}
} your package {
"dependencies": {
"react": "x.x.x",
"react-dom": "x.x.x"
}
} good caseproject {
"dependencies": {
"react": "x.x.x",
"react-dom": "x.x.x",
"your package": "x.x.x"
}
} your package {
++ "peerDependencies": {
"react": "x.x.x",
"react-dom": "x.x.x"
}
} Maybe not right, but hopefully it will help you |
@iDestin , in my example react and react-dom versions are equal, but it causes the bug. |
Hi! For me this helped. In my case it was good way: Also with cleanup wrong way: good way: Good luck! |
THE SOLUTION OF THIS ISSUE IS THIS! :) -> https://iws.io/2022/invalid-hook-multiple-react-instances |
This issue is about |
Try |
Didn't work for me. |
Cannot read properties of null (reading 'useState')
|
Cannot read properties of null (reading 'useState')
|
any updates? |
I'm getting the same error. I was just trying to create various routes for my project. Tried a bunch of stuff but didn't work. It keeps saying: reading usestate. But uptill now I've not even used it yet. |
Can you elaborate a bit, or give a sample code please? I still didn't get that properly. :) edit: |
@haikyuu , could you push this bug to confirmed status based on my comment. |
I was also facing the same issue with storybook. So I switched storybook bundler config from webpack to vite. This has resolved my issue |
I've struggled with this issue all day and I tried everything here but nothing worked for me. At last, I solved it by updating webpack version from 5.36.2 to the latest 5.91.0. |
I'm facing this issue too I moved some dependencies to peerDependencies, which partially solved the issue. However, I'm still facing that issue in a monorepo. My Project: https://github.com/bundlydev/motoko-nextjs-react-native/tree/fix-build My Package: https://github.com/bundlydev/ares/tree/develop |
This solves the error for me, but then I have to repeat this process of replacing the .tgz file after every change in the package, can somebody find more better solutions for this |
Adding a react alias in webpack config works for me:
|
React version: 18.2
Steps To Reproduce
Link to code example: https://scrimba.com/scrim/co257466ea4774401eb77c8a6
Note that you can pause the scrim ("video") to edit code and see the result by yourself.
The current behavior
Crashes without a helpful error message
The expected behavior
Should display a helpful error message.
This issue was reported before but closed because of lack of reproduction code #24774 and #24658
The text was updated successfully, but these errors were encountered: